package com.csk.zsk.compents.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csk.zsk.compents.dao.CodeDao;
import com.csk.zsk.compents.entity.Code;
import com.csk.zsk.compents.service.CodeService;
import com.google.common.collect.Maps;

@Service
@Transactional
public class CodeServiceImpl implements CodeService {

	@Autowired
	private CodeDao codeDao;

	@Override
	public void saveCode(Code code) {
		codeDao.saveBeforeClear(code);
	}

	@Override
	public void deleteCode(String id) {
		codeDao.delete(id);
	}

	@Override
	@Transactional(readOnly = true)
	public Code getCode(String id) {
		return codeDao.get(id);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Code> searchCodeByGroupNo(String groupNo) {
		return codeDao.searchCodeByGroupNo(groupNo);
	}

	@Override
	@Transactional(readOnly = true)
	public Map<String, String> findCodeByGroupNo(String groupNo) {
		Map<String, String> map = Maps.newHashMap();
		List<Code> codeList = codeDao.searchCodeByGroupNo(groupNo);
		for (Code code : codeList) {
			map.put(code.getCodeNo(), code.getName());
		}
		return map;
	}
}
